define(
   [
      'dojo/_base/declare',
      'dojo/on',
      'dojo/dom',
      'dojo/_base/lang',
      'dojo/dom-construct',
      'graphtest/FunctionManager'
   ],
   function(declare, on, dom, lang, domConstruct, FunctionManager)
   {
      return declare([],
      	 {
      	    classCode: 'InitD3Transition',
      	    
      	    constructor:function(args)
      	    {
      	       console.log(this.classCode, "I'm in constructor", this.classCode);
      	    },
      	    
      	    postscript:function()
      	    {
      	      console.log(this.classCode, "I'm in postscript", this.classCode);
      	      
      	      this.width = 600;
      	      this.height = 600;
      	      
      	      this.svg = d3.select("body").append("svg")
      	      .attr("id","svg_transition")
      	      .attr("width", this.width)
      	      .attr("height", this.height)
      	      .attr("class","svg");
      	      
      	      //this.svg.append("rect")
      	      //.attr("width", this.width)
      	      //.attr("height", this.height)
      	      //.attr("class","rect");
      	      
      	      this.rect = this.svg
      	      .append("rect")
      	      .attr("width", 100)
      	      .attr("height", 100)
      	      .attr("x", 0)
      	      .attr("y", 0)
      	      .attr("fill","black")
      	      .call(d3.behavior.drag().on("drag", function(d,i)
      	        {
      	          var rect = d3.select(this);
      	          rect.attr("transform", function(d,i)
      	          {
      	            var edx = d3.event.dx;
      	            var edy = d3.event.dy;
      	            var x = parseFloat(rect.attr("x"));
      	            var y = parseFloat(rect.attr("y"));
      	            x += edx;
      	            y += edy;
      	            rect.attr("x",x);
      	            rect.attr("y",y);
      	            //return "translate(" + [ x,y ] + ")";
      	          });
      	        }));
      	      
      	      //var fmOpt =
      	      //{
      	      //  type: 'mine',
      	      //  startX:0,
      	      //  startY:0,
      	      //  endX:500,
      	      //  endY:500
      	      //};
      	      //
      	      //var fmExp = new FunctionManager(fmOpt);
      	      //var exp = fmExp.fun();
      	      
      	      var duration = 1000;
      	      
      	      function f5()
      	      {
      	        d3.select(this)
      	        .transition()
      	        .duration(duration)
      	        .attr("x",500)
      	        .attr("y",500)
      	        .attr("width",100)
      	        .attr("height",100)
      	        .each("end",null);
      	      }
      	      
      	      function f4()
      	      {
      	        d3.select(this)
      	        .transition()
      	        .duration(duration)
      	        .attr("width",500)
      	        .attr("height",500)
      	        .each("end",f5);
      	      }
      	      
      	      function f3()
      	      {
      	    	  d3.select(this)
      	    	  .transition()
      	    	  .duration(duration)
      	    	  .attr("x",200)
      	    	  .each("end",f4);
      	      }
      	      
      	      function f2()
      	      {
      	    	  d3.select(this)
      	    	  .transition()
      	    	  .duration(duration)
      	    	  .attr("y",200)
      	    	  .each("end",f3);
      	      }
      	      
      	      /*
      	      this.rect
      	      .transition()
      	      .delay(1000)
      	      .duration(duration)
      	      .attr("x",100)
      	      .attr("y",100)
      	      //.attrTween("x",exp.X)
      	      //.attrTween("y",exp.Y)
      	      .style("fill","yellow")
      	      .style("stroke","black")
      	      .each("end",f2);
      	      */
      	    },
      	    
      	    
      	    myFunX:function(d, i, a)
      	    {
      	      return function(t)
      	      {
      	        console.log("t",t);
      	        //return t<0.5 ? 0 : t*150;
      	        return t*300;
      	      };
      	    },
      	    
      	    myFunY:function(d, i, a)
      	    {
      	      return function(t)
      	      {
      	        console.log("t",t);
      	        //return t<0.5 ? t*300 : 150;
      	        return t*300;
      	      };
      	    },
      	    
      	    endOfLib:null
      	 });
   });